using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using BPCSFileDaemon.FileFactory;

using Jamila2.Tools;
using Jamila2.Database;

namespace BPCSFileDaemon
{
    public class FileAnalyzer  : FileSystemWatcher
    {
        protected string ArchievedPath = "", LogPath = "";                

        public FileAnalyzer(string ArchievedPath, string SourcePath, string LogPath)
        {
            this.ArchievedPath = ArchievedPath;            
            this.LogPath = LogPath;

            base.Path = SourcePath;                        
            base.Created += new FileSystemEventHandler(FileDaemonWatcher_Created);

        }

        void FileDaemonWatcher_Created(object sender, FileSystemEventArgs e)
        {
            //this.StartAnalyzing(e.FullPath, e.Name);

            if (File.Exists(e.FullPath))
            {
                string FileName = e.Name.Substring(0, e.Name.IndexOf("."));
                string FileType = FileName.Substring(7, 1);
                string Entity = FileName.Substring(8, 2);

                Console.WriteLine("Incoming File: " + e.FullPath + "/" + FileName + "/" + FileType + "/" + Entity);
                this.StartAnalyzing(e.FullPath, e.Name);

                

                #region Remarks: Testing

                /*
                StreamReader sr = null;
                try
                {
                    sr = new StreamReader(e.FullPath, Encoding.UTF8);
                    string line;
                    // Read and display lines from the file until the end of 
                    // the file is reached.
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }

                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: " + ex.Message);
                }
                finally
                {
                    sr.Close();
                    sr = null;
                }

                */
                #endregion
            }
        }

        protected void StartAnalyzing(string path, string name)
        {
            


            
        }
        
    }
}
